home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / WASTE 1.1b1 Distribution / Demo Source / WEDemoIntf.p < prev    next >
Text File  |  1995-06-01  |  6KB  |  265 lines

  1. unit WEDemoIntf;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Global interface: constant, type and class declarations used in most other units }
  5.  
  6. { Copyright © 1993-1995 Marco Piovanelli }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         Types, Resources, Quickdraw, Menus, Windows, Controls, WASTE;
  12.  
  13.     const
  14.  
  15. { WASTE demo signature }
  16.  
  17.         kAppSignature = 'OEDE';
  18.  
  19. { resource types, clipboard types and file types }
  20.  
  21.         kTypeDeskAccessory = 'DRVR';
  22.         kTypeFont = 'FONT';
  23.         kTypePicture = 'PICT';
  24.         kTypeSound = 'snd ';
  25.         kTypeSoup = 'SOUP';
  26.         kTypeStyles = 'styl';
  27.         kTypeText = 'TEXT';
  28.  
  29. { menu IDs }
  30.  
  31.         kMenuApple = 1;
  32.         kMenuFile = 2;
  33.         kMenuEdit = 3;
  34.         kMenuFont = 4;
  35.         kMenuSize = 5;
  36.         kMenuStyle = 6;
  37.         kMenuColor = 7;
  38.         kMenuFeatures = 8;
  39.         kMenuAlignment = 9;
  40.  
  41. { Apple menu items }
  42.  
  43.         kItemAbout = 1;
  44.  
  45. { File menu items }
  46.  
  47.         kItemNew = 1;
  48.         kItemOpen = 2;
  49.         kItemClose = 4;
  50.         kItemSave = 5;
  51.         kItemSaveAs = 6;
  52.         kItemQuit = 8;
  53.  
  54. { Edit menu items }
  55.  
  56.         kItemUndo = 1;
  57.         kItemCut = 3;
  58.         kItemCopy = 4;
  59.         kItemPaste = 5;
  60.         kItemClear = 6;
  61.         kItemSelectAll = 7;
  62.  
  63. { Size menu items }
  64.  
  65.         kItemLastSize = 6;
  66.         kItemSmaller = 8;
  67.         kItemLarger = 9;
  68.  
  69. { Style menu items }
  70.  
  71.         kItemPlainText = 1;
  72.         kItemBold = 2;
  73.         kItemItalic = 3;
  74.         kItemUnderline = 4;
  75.         kItemOutline = 5;
  76.         kItemShadow = 6;
  77.         kItemCondensed = 7;
  78.         kItemExtended = 8;
  79.  
  80. { Color menu items }
  81.  
  82.         kItemBlack = 1;
  83.         kItemRed = 2;
  84.         kItemGreen = 3;
  85.         kItemBlue = 4;
  86.         kItemCyan = 5;
  87.         kItemMagenta = 6;
  88.         kItemYellow = 7;
  89.  
  90. { Alignment menu items }
  91.  
  92.         kItemAlignDefault = 1;
  93.         kItemAlignLeft = 3;
  94.         kItemCenter = 4;
  95.         kItemAlignRight = 5;
  96.         kItemJustify = 6;
  97.  
  98. { Features menu item }
  99.  
  100.         kItemAlignment = 1;
  101.         kItemTabHooks = 2;
  102.         kItemAutoScroll = 4;
  103.         kItemOutlineHilite = 5;
  104.         kItemReadOnly = 6;
  105.         kItemIntCutAndPaste = 7;
  106.         kItemDragAndDrop = 8;
  107.         kItemOffscreenDrawing = 9;
  108.  
  109. { Alert & dialog template resource IDs }
  110.  
  111.         kAlertNeedSys7 = 128;
  112.         kAlertGenError = 130;
  113.         kAlertSaveChanges = 131;
  114.         kDialogAboutBox = 256;
  115.  
  116. { String list resource IDs }
  117.  
  118.         kUndoStringsID = 128;
  119.         kClosingQuittingStringsID = 129;
  120.  
  121. { miscellaneous resource IDs }
  122.  
  123.         kMenuBarID = 128;
  124.         kWindowTemplateID = 128;
  125.         kScrollBarTemplateID = 128;
  126.         kPromptStringID = 128;
  127.  
  128. { virtual key codes for navigation keys found on extended keyboards }
  129.  
  130.         keyPgUp = $74;
  131.         keyPgDn = $79;
  132.         keyHome = $73;
  133.         keyEnd = $77;
  134.  
  135. { values for HiliteControl hiliteState parameter }
  136.  
  137.         kCtlActive = 0;                    { active control }
  138.         kCtlHilited = 1;                    { highlighted active control }
  139.         kCtlBackground = 254;        { inactive control in an inactive window }
  140.         kCtlInactive = 255;            { inactive control in the active window }
  141.  
  142. { other commonly used constants }
  143.  
  144.         kBarWidth = 16;                { width of a scroll bar }
  145.         kTitleHeight = 20;                { usual height of a window title bar }
  146.         kTextMargin = 3;                { indent of text rect from window port rect }
  147.         kScrollDelta = 11;                { pixels to scroll when the scroll bar arrow is clicked }
  148.  
  149.     type
  150.  
  151. { enumeration types used for closing a window and/or quitting the application }
  152.  
  153.         ClosingOption = (closingWindow, closingApplication);
  154.         SavingOption = (savingYes, savingNo, savingAsk);
  155.  
  156. { a ScrollBarPair is just a pair of control handles }
  157.  
  158.         ScrollBarPair = record
  159.                 case Integer of
  160.                     0: (
  161.                             v, h: ControlRef;
  162.                     );
  163.                     1: (
  164. {$IFC NOT UNDEFINED THINK_PASCAL}
  165.                             vh: array[VHSelect] of ControlRef;
  166. {$ELSEC}
  167.                             vh: array[0..1] of ControlRef;
  168. {$ENDC}
  169.                     );
  170.             end;  { ScrollBarPair }
  171.  
  172. { a DocumentRecord is a window record with additional fields }
  173.  
  174.         DocumentRecord = record
  175.                 window: WindowRecord;                    { the window }
  176.                 scrollBars: ScrollBarPair;                    { its scroll bars }
  177.                 hWE: WEHandle;                                { its WASTE instance }
  178.                 fileAlias: Handle;                                { alias to associated file }
  179.             end;  { DocumentRec }
  180.         DocumentPeek = ^DocumentRecord;
  181.  
  182.     var
  183.  
  184. { global variables }
  185.  
  186.         gHasColorQD: Boolean;            { TRUE if Color QuickDraw is available }
  187.         gHasDragAndDrop: Boolean;    { TRUE if the Drag Manager is available }
  188.         gHasTextServices: Boolean;    { TRUE if the Text Services Manager is available }
  189.         gExiting: Boolean;                    { set this variable to drop out of event loop and quit }
  190.  
  191. { general purpose utility routines }
  192.  
  193.     procedure ErrorAlert (err: OSErr);
  194.     procedure ForgetHandle (var h: univ Handle);
  195.     procedure ForgetResource (var h: univ Handle);
  196.     function NewHandleTemp (blockSize: Size;
  197.                                     var h: univ Handle): OSErr;
  198.  
  199. implementation
  200.     uses
  201.         DialogUtils;
  202.  
  203.     procedure ErrorAlert (err: OSErr);
  204.         var
  205.             errString: Str255;
  206.             alertResult: Integer;
  207.     begin
  208.         NumToString(err, errString);
  209.         ParamText(errString, '', '', '');
  210. {$IFC NOT UNDEFINED THINK_PASCAL}
  211.         SetCursor(arrow);
  212. {$ELSEC}
  213.         SetCursor(qd.arrow);
  214. {$ENDC}
  215.         alertResult := Alert(kAlertGenError, GetMyStandardDialogFilter);
  216.     end;  { ErrorAlert }
  217.  
  218.     procedure ForgetHandle (var h: univ Handle);
  219.         var
  220.             theHandle: Handle;
  221.     begin
  222.         theHandle := h;
  223.         if (theHandle <> nil) then
  224.             begin
  225.                 h := nil;
  226.                 DisposeHandle(theHandle);
  227.             end;
  228.     end;  { ForgetHandle }
  229.  
  230.     procedure ForgetResource (var h: univ Handle);
  231.         var
  232.             theHandle: Handle;
  233.     begin
  234.         theHandle := h;
  235.         if (theHandle <> nil) then
  236.             begin
  237.                 h := nil;
  238.                 ReleaseResource(theHandle);
  239.             end;
  240.     end;  { ForgetResource }
  241.  
  242.     function NewHandleTemp (blockSize: Size;
  243.                                     var h: univ Handle): OSErr;
  244.  
  245. { allocate a new relocatable block from temporary memory or, }
  246. { if that fails, from the current heap }
  247.  
  248.         var
  249.             err: OSErr;
  250.     begin
  251.  
  252. { first try tapping temporary memory }
  253.         h := TempNewHandle(blockSize, err);
  254.         NewHandleTemp := err;
  255.  
  256. { in case of failure, try with current heap }
  257.         if (h = nil) then
  258.             begin
  259.                 h := NewHandle(blockSize);
  260.                 NewHandleTemp := MemError;
  261.             end;
  262.  
  263.     end;  { NewHandleTemp }
  264.  
  265. end.